14. Encapsulation
Encapsulation
Encapsulation
Encapsulation is the grouping together of data and logic into a single unit. In object-oriented programming, classes encapsulate data and functions that operate on that data.
This can be a delicate balance, because on the one hand we want to group together relevant data and functions, but on the hand we want to limit member functions to only those functions that need direct access to the representation of a class.
In the context of a Date
class, a function Date Tomorrow(Date const & date)
probably does not need to be encapsulated as a class member. It can exist outside the Date
class.
However, a function that calculates the number of days in a month probably should be encapsulated with the class, because the class needs this function in order to operate correctly.
Workspace
This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity, so you may be able to download them there.
Workspace Information:
- Default file path:
- Workspace type: jupyter
- Opened files (when workspace is loaded): n/a